package com.ruoyi.web.controller.ddsystem;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DdOrder;
import com.ruoyi.system.service.IDdOrderService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import sun.awt.windows.WPrinterJob;

/**
 * 订单信息Controller
 * 
 * @author ruoyi
 * @date 2020-02-19
 */
@Controller
@RequestMapping("/system/order")
public class DdOrderController extends BaseController
{
    private String prefix = "system/order";

    @Autowired
    private IDdOrderService ddOrderService;

    @RequiresPermissions("system:order:view")
    @GetMapping("/open")
    public String order(Model model)
    {
//        model.addAttribute("status", "1");
        return prefix + "/order";
    }
    @RequiresPermissions("system:order:view")
    @GetMapping("/orderUn")
    public String orderUn(Model model)
    {
//        model.addAttribute("status", "0");
        return prefix + "/order";
    }

    /**
     * 查询订单信息列表
     */
    @RequiresPermissions("system:order:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DdOrder ddOrder)
    {
        startPage();
        List<DdOrder> list = ddOrderService.selectDdOrderList(ddOrder);
        return getDataTable(list);
    }

    /**
     * 导出订单信息列表
     */
    @RequiresPermissions("system:order:export")
    @Log(title = "订单信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DdOrder ddOrder)
    {
        List<DdOrder> list = ddOrderService.selectDdOrderList(ddOrder);
        ExcelUtil<DdOrder> util = new ExcelUtil<DdOrder>(DdOrder.class);
        return util.exportExcel(list, "order");
    }

    /**
     * 新增订单信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存订单信息
     */
    @RequiresPermissions("system:order:add")
    @Log(title = "订单信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DdOrder ddOrder)
    {
        return toAjax(ddOrderService.insertDdOrder(ddOrder));
    }

    /**
     * 修改订单信息
     */
    @GetMapping("/edit/{uuid}")
    public String edit(@PathVariable("uuid") String uuid, ModelMap mmap)
    {
        DdOrder ddOrder = ddOrderService.selectDdOrderById(uuid);
        mmap.put("ddOrder", ddOrder);
        return prefix + "/edit";
    }

    /**
     * 修改保存订单信息
     */
    @RequiresPermissions("system:order:edit")
    @Log(title = "订单信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DdOrder ddOrder)
    {
        return toAjax(ddOrderService.updateDdOrder(ddOrder));
    }

    /**
     * 删除订单信息
     */
    @RequiresPermissions("system:order:remove")
    @Log(title = "订单信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ddOrderService.deleteDdOrderByIds(ids));
    }
}
